package com.zzh.tree;

public class No100_isSameTree {
    public static void main(String[] args) {
        No100Solution solution = new No100Solution();
        TreeNode p = new TreeNode(1);
        TreeNode q = new TreeNode(1);
        p.left = new TreeNode(2);
        p.right = new TreeNode(3);
        q.left = new TreeNode(2);
        q.right = new TreeNode(3);
        boolean sameTree = solution.isSameTree(p, q);
        System.out.println(sameTree);
    }
}

class No100Solution {
    public boolean isSameTree(TreeNode p, TreeNode q) {
        if (p == null && q == null) {
            return true;
        }
        if (p == null || q == null) {
            return false;
        }

        if (p.val != q.val) {
            return false;
        }

        return isSameTree(p.left, q.left) && isSameTree(p.right, q.right);
    }
}

